﻿@using System.Reflection
@using System.Runtime.Versioning
<h3 class="text-info">日记目录</h3>
<div class="border rounded-3 p-3">
    <ul class="nav flex-column">
        @{
            string basePath;
            if (System.Diagnostics.Debugger.IsAttached)
            {
                var net_version = GetTargetFrameworkVersion.GetTargetFrameworkMoniker();
                // 开发环境，日志文件在 bin/debug/net8.0/logs 文件夹中
                basePath = Path.Combine(Directory.GetCurrentDirectory(), "bin", "debug", net_version, "Logs");
            }
            else
            {
                // 发布环境，日志文件在 logs 文件夹中
                basePath = Path.Combine(Directory.GetCurrentDirectory(), "Logs");
            }
        }
        @foreach (var category in Directory.GetDirectories(basePath))
        {
            <li class="nav-item">
                <span @onclick="() => ToggleCategory(category)">@Path.GetFileName(category)</span>
                @if (_expandedCategories.Contains(category))
                {
                    <ul>
                        @foreach (var file in Directory.GetFiles(category, "*.log"))
                        {
                            <li>
                                <span @onclick="() => OnFileClick(file)">@Path.GetFileName(file)</span>
                            </li>
                        }
                    </ul>
                }
            </li>
        }
    </ul>
</div>
